<template>
  <div class="su-material-container">
    <el-tabs v-model="activeName" @tab-click="tabClick">
      <el-tab-pane label="Total" name="total">
        <div class="table-cover">
          <el-table
            :data="totalList"
            stripe
            style="width: 100%">
            <el-table-column
              prop="id"
              label="ID"
              width="100">
            </el-table-column>
            <el-table-column
              prop="name"
              label="Name"
              width="300"
            >
            </el-table-column>
            <el-table-column
              prop="last"
              label="Stock"
            ></el-table-column>
          </el-table>
          <div class="block">
            <el-pagination
              background
              layout="prev, pager, next"
              :page-size="10"
              :total="this.api.materialIndex.length-1"
              @current-change="changepagetotal"
            >
            </el-pagination>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane v-for="i in 10" :key="i" :label="'Branch'+i" :name="'branch'+i">
        <branch :id="i"></branch>
      </el-tab-pane>
    </el-tabs>


  </div>
</template>

<script>
  import Branch from './GDFunctionSuMaterialBranch'

  export default {
    name: "GDFunctionSuMaterial",
    components: {
      Branch
    },
    data() {
      return {
        activeName: 'total',
        pageIndex: [],

      }
    },
    methods: {
      tabClick(e) {
        this.$store.commit('setBranchSelect', e.name);
        this.$store.commit('setBranchList', this.api.getBranchStore(parseInt(e.index) - 1, 0));
      },
      handleClick(e) {
        // this.$store.commit('setBranchList',this.api.getBranchStore(parseInt(e.index)-1,0));
      },
      changepagetotal(page) {
        this.$store.commit('setTotalList', this.api.getTotalList(page - 1));
      }
    },
    mounted() {
      this.activeName = this.$store.state.branchSelect;
      for (let i = 0; i < 12; i++) {
        this.pageIndex[i] = 1;
        this.$store.commit('setTotalList', this.api.getTotalList(0));
      }
    },
    computed: {
      totalList() {
        return this.$store.state.totalList;
      },

    }
  }
</script>

<style scoped>
  .su-material-container {
    width: calc(100% - 20px);
    height: 100%;
    border-radius: 4px;
    margin-left: 10px;
    margin-right: 10px;
  }

  .block {
    margin-left: calc(50%);
    margin-top: 20px;
    transform: translateX(-50%);
  }

  .table-cover {
    margin-bottom: 20px;
    background: #fff;
    border-radius: 4px;
    width: calc(100% - 20px);
  }
</style>
